// pages/mall/mall.js
const app = getApp()
Page({
  data: {
    total:0,
    _num : 0,
    ishas: 0,
    city : "",
    month: 7,
    num  : 1,
    userback: [
      {address: "西安",name: "牛闪闪",money: "100",}
    ],
    movies: [],
    thrclassify:[],
    goods:[]
  },
  //搜索商品
  search     : function () { wx.navigateTo({ url: '../search/search',}) },
  recordjl   : function () { wx.navigateTo({ url: '../recordjl/recordjl',}) },
  chose_city : function () { wx.navigateTo({ url: '../address/address', }) }, // 选择地址
  focus_click: function(e){
    var that=this;
    wx.showLoading({title: '加载中'})
    wx.request({
      url    : app.url + '/Goods/goods',
      data   : { 
        cid : e.target.id,
        uid : wx.getStorageSync('uid')
      },
      method : 'post',
      success: function (resgoods) {
        if (resgoods.data.code == 1) { 
          that.setData({ goods: resgoods.data.data })
        }else{
           that.setData({ goods: [] }) }
      }
    })
    this.setData({ _num: e.target.dataset.num })
    wx.hideLoading()
  },
  isChose:function(e){
    if (e.target.dataset.ishas == 0){
      this.setData({ bg_color : "#f15c3a",ishas: 1, })
    }else{
      this.setData({ bg_color : "#fff",   ishas: 0, })
    }   
  },
  clickurl:function(e){
    var gid = e.currentTarget.id
    wx.navigateTo({ url: '../goodsDetails/goodsDetails?gid='+gid+'&types=1&bid=0',})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 轮播图计时器
    let that     = this;
    var index    = 0;
    var userback = that.data.userback;
    var num_     = that.data.num;
    var interval = setInterval(function () {
      index = index + 1; num_ = num_ + 1
      that.setData({ num: num_, uploadUrl: app.uploadUrl })
      if (index == userback.length) { that.setData({ num: 1 }); index = 0; num_ = 1 }
    }, 1500)
    wx.request({
      url     : app.url + '/Goods/goods_type',
      data    : { uid: wx.getStorageSync('uid')},
      method  : 'post',
      success : function (res) {
        if(res.data.code == 1){
          that.setData({ thrclassify: res.data.data })
          wx.request({
            url    : app.url + '/Goods/goods',
            data   : { 
              cid: res.data.data[0].cid,
              uid: wx.getStorageSync('uid')
            },
            method : 'post',
            success: function (ress) {
              if (ress.data.code == 1) {
                 that.setData({ goods: ress.data.data })
              }else{
                 that.setData({ goods: [] }) }
            }
          })
        }
      }
    }) 
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this
    that.setData({
      city:app.data.address.name,
      isboss: app.data.isboss
    })
    wx.request({
      url: app.url + '/Reback/total_num',
      method: 'post',
      success: function (res) {
        that.setData({
          total: res.data.data
        })
      }
    });
  },
  get_goods:function(){
     
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  }, /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  index : function(){ wx.redirectTo({ url: "../index/index"}) },
  issue : function(){ wx.redirectTo({ url: "../issue/issue"}) },
  car   : function(){ wx.redirectTo({ url: "../car/car"}) },
  mine  : function(){ wx.redirectTo({ url: "../mine/mine" }) },
})